package com.fxu.tpl.api;

import com.fxu.framework.biz.api.ApiBizController;
import com.fxu.framework.biz.holder.UploadHolder;
import com.fxu.framework.biz.rest.ApiProxyRest;
import com.fxu.framework.core.base.Constant;
import com.fxu.framework.core.base.Result;
import com.fxu.framework.core.holder.RequestHolder;
import com.fxu.tpl.rest.ApiTplRestImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

/***
 * <p>fxu</p>
 * 总控制层
 * @author fangxu
 * @version 2021-03-13
 ***/
@RestController
@RequestMapping("/api/v6")
@Api(tags = "通用接口")
@RequiredArgsConstructor
public class ApiTplController extends ApiBizController {
	private final ApiTplRestImpl apiRestImpl;

	@Override
	protected ApiProxyRest apiNewImpl() {
		return apiRestImpl;
	}

	/*=========================================上传文件=========================================*/
	@ResponseBody
	@PostMapping(value="/upload/", consumes = "multipart/*", headers="content-type=multipart/form-data")
	@ApiOperation(httpMethod = "POST", value = "上传文件", produces = MediaType.APPLICATION_JSON_VALUE)
	@ApiImplicitParams({
			@ApiImplicitParam(name="file", paramType="form", value="临时文件", dataType="File", required=true),
	})
	public Result<UploadHolder.UploadBack> upload(@RequestPart(value = "file") MultipartFile file) {
		String directory = RequestHolder.getRequestNotNull().getHeader(Constant.HEADER_CODE);
		return UploadHolder.getHolder().uploadAliyunOss("talentDao/" + directory, file);
	}

	@ResponseBody
	@PostMapping(value="/uploadLocal/", consumes = "multipart/*", headers="content-type=multipart/form-data")
	@ApiOperation(httpMethod = "POST", value = "上传文件", produces = MediaType.APPLICATION_JSON_VALUE)
	@ApiImplicitParams({
			@ApiImplicitParam(name="file", paramType="form", value="临时文件", dataType="File", required=true),
	})
	public Result<UploadHolder.UploadBack> uploadLocal(@RequestPart(value = "file") MultipartFile file) {
		String directory = RequestHolder.getRequestNotNull().getHeader(Constant.HEADER_CODE);
		return UploadHolder.getHolder().uploadLocal(directory, file);
	}
	/*=========================================上传文件=========================================*/
}